package dao.impl;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import bean.User;
import dao.UserDAO;
import dao.mapper.UserMapper;

import java.util.List;

@Repository(value = "dao")
public class UserDAOImpl extends SqlSessionDaoSupport implements UserDAO {
    public UserDAOImpl(@Autowired SqlSessionFactory sessionFactory) {
        setSqlSessionFactory(sessionFactory);
    }

    public boolean add(User temp) {
        return getSqlSession().getMapper(UserMapper.class).ins(temp);
    }

    public boolean mod(User temp) {
        return getSqlSession().getMapper(UserMapper.class).upd(temp);
    }

    public boolean rem(int integer) {
        return getSqlSession().getMapper(UserMapper.class).del(integer);
    }

    public User que(int integer) {
        return getSqlSession().getMapper(UserMapper.class).selById(integer);
    }

    public List<User> que(User temp) {
        return getSqlSession().getMapper(UserMapper.class).selByOthers(temp);
    }
}
